class PresencesController < ApplicationController
  before_filter :login_required
  
  # GET /presences
  # GET /presences.xml
  def index
    @presences = Presence.find(:all)

    respond_to do |format|
      format.html # index.rhtml
      format.xml  { render :xml => @presences.to_xml }
    end
  end

  # GET /presences/1
  # GET /presences/1.xml
  def show
    @presence = Presence.find(params[:id])

    respond_to do |format|
      format.html # show.rhtml
      format.xml  { render :xml => @presence.to_xml }
    end
  end

  # GET /presences/new
  def new
    @presence = Presence.new
  end

  # GET /presences/1;edit
  def edit
    @presence = Presence.find(params[:id])
  end

  # POST /presences
  # POST /presences.xml
  def create
    @presence = current_user.presences.create(params[:presence])

    respond_to do |format|
      if @presence
        flash[:notice] = 'Presence was successfully created.'
        format.html { redirect_to presence_url(:user_id => current_user, :id => @presence) }
        format.xml  { head :created, :location => presence_url(@presence) }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @presence.errors.to_xml }
      end
    end
  end

  # PUT /presences/1
  # PUT /presences/1.xml
  def update
    @presence = Presence.find(params[:id])

    respond_to do |format|
      if @presence.update_attributes(params[:presence])
        flash[:notice] = 'Presence was successfully updated.'
        format.html { redirect_to presence_url(@presence) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @presence.errors.to_xml }
      end
    end
  end

  # DELETE /presences/1
  # DELETE /presences/1.xml
  def destroy
    @presence = Presence.find(params[:id])
    @presence.destroy

    respond_to do |format|
      format.html { redirect_to presences_url }
      format.xml  { head :ok }
    end
  end
  
end
